#ifndef __GGEAR_IMAGE_H
#define __GGEAR_IMAGE_H

#include "ggear_types.h"
#include "ggear_color.h"
#include "ggear_point2.h"
#include "ggear_string.h"
#include "ggear_allocator.h"

namespace ggear
{
	namespace gfx
	{
		class Image
		{
		public:
			enum PixelFormat
			{
				//! 24 bits per pixel . Each component Red, Green, Blue has 8 bits . No alpha component
				PixelFormat_R8G8B8,
				
				//! Default format . Each component Red, Green, Blue and Alpha has 8 bits
				PixelFormat_R8G8B8A8,
				
				//! 16 bits per pixel . Each component Red, Green, Blue and Alpha has 4 bits
				PixelFormat_R4G4B4A4,

				//! 16 bits per pixel . Each component Red, Green , Blue has 5 bits . 1 bit for Alpha
				PixelFormat_R5G5B5A1,

				//! 16 bits per pixel . Red and Blue has 5 bits . 6 bits for Green
				PixelFormat_R5G6B5,

				//! 16 bits per pixel . Used to specify 65536 shades of gray
				PixelFormat_GRAYSCALE16,
			};

		private:
			//! Default constructor.
			Image();

		public:			
			//! Create a new image from an existing image
			Image(const Image& _img);

			//! Create clean black image with specified width , height and pixel format
			Image(u32 _width, u32 _height, PixelFormat _pxFmt);

			//! Create image from byte array
			Image(const u8* const _data, u32 _width, u32 _height, PixelFormat _pxFmt);

			//! Destructor
			~Image();

			//! Return width of image
			u32 Width() const;

			//! Return height of image
			u32 Height() const;

			//! Return type of pixel format
			PixelFormat ColorFormat() const;

			//! Return the color depth of image
			u8 ColorBits() const;

			//! Return bit mask of red component
			u32 RedMask() const;

			//! Return bit mask of green component
			u32 GreenMask() const;

			//! Return bit mask of blue component
			u32 BlueMask() const;

			//! Return bit mask of a;pha component
			u32 AlphaMask() const;

			//! Return pointer to byte array of current image
			u8* Lock();

			void Unlock();

			//! Return constant pointer to byte array of current image
			const u8* Data() const;

			//! Get color of pixel at specified position
			Color GetPixel(u32 _x, u32 _y) const;

			Color GetPixel(const Point2u& _pos) const;

			//! Set color of pixel at specified position
			void SetPixel(u32 _x, u32 _y, const Color& _clr);

			void SetPixel(const Point2u& _pos, const Color& clr);

			//! Release resources being used by image
			void Dispose();

			Image& operator = (const Image& _img);

		private:
			u8* mData;
			u32 mWidth;
			u32 mHeight;
			PixelFormat mPixelFmt;
			glb::Allocator<u8> mAlloc;
		};
	}
}

#endif